package oa.hleast.xswl.service.oms.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ijpay.core.kit.HttpKit;
import com.ijpay.core.kit.WxPayKit;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.enums.BusinessTypeEnum;
import oa.hleast.common.pay.config.WxPayConfig;
import oa.hleast.common.redis.component.BusinessNoGenerator;
import oa.hleast.common.redis.component.template.RedisRepository;
import oa.hleast.common.result.Result;
import oa.hleast.common.utils.ImagerListUtil;
import oa.hleast.common.utils.JsonUtil;
import oa.hleast.common.web.exception.BizException;
import oa.hleast.common.web.util.RequestUtils;
import oa.hleast.common.wx.config.WeAppConfig;
import oa.hleast.xswl.common.constant.OmsConstants;
import oa.hleast.xswl.common.constant.ReviewStatusEnum;
import oa.hleast.xswl.common.enums.*;
import oa.hleast.xswl.mapper.oms.OmsOrderCommentReplyMapper;
import oa.hleast.xswl.mapper.oms.OrderMapper;
import oa.hleast.xswl.pojo.domain.UmsAddress;
import oa.hleast.xswl.pojo.domain.oms.*;
import oa.hleast.xswl.pojo.domain.pms.PmsMarketingField;
import oa.hleast.xswl.pojo.domain.pms.PmsPointThing;
import oa.hleast.xswl.pojo.domain.pms.PmsSpu;
import oa.hleast.xswl.pojo.domain.pms.PmsUserCoupon;
import oa.hleast.xswl.pojo.domain.store.StoreInfo;
import oa.hleast.xswl.pojo.dto.SysUserDto;
import oa.hleast.xswl.pojo.dto.UmsUserDto;
import oa.hleast.xswl.pojo.dto.oms.OrderConfirmDTO;
import oa.hleast.xswl.pojo.dto.oms.OrderItemDTO;
import oa.hleast.xswl.pojo.dto.oms.OrderSubmitDTO;
import oa.hleast.xswl.pojo.dto.pms.SkuDTO;
import oa.hleast.xswl.pojo.dto.pms.SkuLockDTO;
import oa.hleast.xswl.pojo.dto.store.StoreInfoDto;
import oa.hleast.xswl.pojo.form.oms.OmsOrderCommentForm;
import oa.hleast.xswl.pojo.form.oms.OrderCommentForm;
import oa.hleast.xswl.pojo.vo.oms.*;
import oa.hleast.xswl.pojo.vo.store.BaseStoreInfo;
import oa.hleast.xswl.pojo.vo.store.StorePayInfoConfig;
import oa.hleast.xswl.service.ISysUserService;
import oa.hleast.xswl.service.IUmsAddressService;
import oa.hleast.xswl.service.IUmsUserService;
import oa.hleast.xswl.service.oms.*;
import oa.hleast.xswl.service.pay.WeiXinPayClientService;
import oa.hleast.xswl.service.pms.*;
import oa.hleast.xswl.service.store.StoreInfoService;
import oa.hleast.xswl.service.store.StorePayInfoService;
import oa.hleast.xswl.utils.GlobalExpressUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;


@AllArgsConstructor
@Slf4j
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> implements IOrderService {

    private ICartService cartService;
    private IPmsSkuService skuFeignService;
    private IOrderItemService orderItemService;
    private RabbitTemplate rabbitTemplate;
    private RedisRepository redisRepository;
    private BusinessNoGenerator businessNoGenerator;
    private IOrderDeliveryService orderDeliveryService;
    private IUmsUserService umsUserService;
    private PmsUserCouponService pmsCouponFeignService;
    private IUmsAddressService addressFeignService;
    private PmsPointThingService pmsPointThingFeignService;
    private PmsMarketingFieldService pmsMarketingFieldService;
    private IPmsSpuService pmsSpuService;
    private final StoreInfoService storeInfoService;
    private final WeAppConfig weAppConfig;
    private final ISysUserService sysUserService;
    private final WxPayConfig wxPayConfig;
    private final StorePayInfoService storePayInfoService;
    private final OmsOrderCommentService commentService;
    private final OmsOrderCommentReplyMapper replyMapper;
    private final OmsOrderRefundService orderRefundService;


//    private MemberFeignService memberFeignService;
//    private PmsSkuFeignService skuFeignService;
//    private PmsCouponFeignService pmsCouponFeignService;
//
//    private UmsAddressFeignService addressFeignService;
//
//    private PmsPointThingFeignService pmsPointThingFeignService;
//
//    private PmsMarketingFieldFeignService pmsMarketingFieldFeignService;

    @Override
    public OmsOrderVo detail(Long orderId) {
        OmsOrder omsOrder = this.getById(orderId);
        List<OmsOrderItem> omsOrderItemList = orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, orderId));
        omsOrder.setOrderItems(omsOrderItemList);

        OmsOrderDelivery omsOrderDelivery = orderDeliveryService.getOne(new LambdaQueryWrapper<OmsOrderDelivery>().eq(OmsOrderDelivery::getOrderId, orderId));
        omsOrder.setOmsOrderDelivery(omsOrderDelivery);


        // 限时购、拼团和众筹
        if (omsOrder.getOrderType().equals(OrderTypeEnum.GROUP.getCode())
                || omsOrder.getOrderType().equals(OrderTypeEnum.CROWDFUNDING.getCode())
                || omsOrder.getOrderType().equals(OrderTypeEnum.SECKILL.getCode())) {
            omsOrder.setPmsMarketingField(pmsMarketingFieldService.getById(omsOrder.getRelativeId()));
        }

        OmsOrderVo omsOrderVo = new OmsOrderVo();
        BeanUtil.copyProperties(omsOrder, omsOrderVo);
        // 店铺信息
        StoreInfo storeInfo = storeInfoService.getById(omsOrder.getStoreId());
        BaseStoreInfo storeInfoVo = new BaseStoreInfo();

        BeanUtil.copyProperties(storeInfo, storeInfoVo);
        omsOrderVo.setStoreInfo(storeInfoVo);

        return omsOrderVo;
    }

    /**
     * 订单确认
     */
    @Override
    public OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO) {
        Long memberId = RequestUtils.getUserId();
        // 营销场每个场次每个用户只能参与一次
        if (orderConfirmDTO.getOrderType().equals(OrderTypeEnum.SECKILL.getCode())
                || orderConfirmDTO.getOrderType().equals(OrderTypeEnum.GROUP.getCode())
                || orderConfirmDTO.getOrderType().equals(OrderTypeEnum.CROWDFUNDING.getCode())
        ) {

            if (this.count(new LambdaQueryWrapper<OmsOrder>().eq(OmsOrder::getMemberId, memberId)
                    .ge(OmsOrder::getStatus, OrderStatusEnum.PAID.getCode())
                    .eq(OmsOrder::getRelativeId, orderConfirmDTO.getRelativeId())) > 0) {
                throw new BizException("你已经参与过该营销场活动， 谢谢！！");
            }

        }


        log.info("=======================订单确认=======================\n订单确认信息：{}", orderConfirmDTO);
        OrderConfirmVO orderConfirmVO = new OrderConfirmVO();
        // 获取购买商品信息
//        CompletableFuture<Void> orderItemsCompletableFuture = CompletableFuture.runAsync(() -> {
        List<OrderItemDTO> orderItems = new ArrayList<>();
        Long totalPrice = 0L;
        if (orderConfirmDTO.getSkuId() != null) {
            // 直接购买商品结算
            OrderItemDTO orderItemDTO = OrderItemDTO.builder()
                    .skuId(orderConfirmDTO.getSkuId())
                    .count(orderConfirmDTO.getCount())
                    .build();
            SkuDTO sku = skuFeignService.getSkuById(orderConfirmDTO.getSkuId());

            orderItemDTO.setSpuId(sku.getSpuId());
            orderItemDTO.setPic(sku.getPicUrl());
            orderItemDTO.setSkuName(sku.getName());
            orderItemDTO.setSkuCode(sku.getCode());
            orderItemDTO.setSpuName(sku.getSpuName());
            orderItems.add(orderItemDTO);
            Long price = getOrderPrice(orderConfirmDTO.getOrderType(), orderConfirmDTO.getSkuId(), sku.getPrice());
            log.info("skuPrice = {},price = {}", sku.getPrice(), price);
            orderItemDTO.setPrice(price);
            totalPrice = price * orderConfirmDTO.getCount();
        } else {
            // 购物车中商品结算  不支持营销场
            List<CartVO.CartItem> cartItems = cartService.getCartItems(memberId);
            List<OrderItemDTO> items = cartItems.stream()
                    .filter(CartVO.CartItem::getChecked)
                    .map(cartItem -> OrderItemDTO.builder()
                            .skuId(cartItem.getSkuId())
                            .count(cartItem.getCount())
                            .price(cartItem.getPrice())
                            .skuName(cartItem.getSkuName())
                            .skuCode(cartItem.getSkuCode())
                            .spuName(cartItem.getSpuName())
                            .pic(cartItem.getPic())
                            .totalPrice(cartItem.getCount() * cartItem.getPrice())
                            .build())
                    .collect(Collectors.toList());
            orderItems.addAll(items);
            totalPrice = items.stream().mapToLong(OrderItemDTO::getTotalPrice).sum();
        }
        orderConfirmVO.setOrderItems(orderItems);
        orderConfirmVO.setOrderType(orderConfirmDTO.getOrderType());
        orderConfirmVO.setRelativeId(orderConfirmDTO.getRelativeId());
        if (orderConfirmVO.getOrderType().equals(OrderTypeEnum.SHOP.getCode())) {
            List<PmsUserCoupon> pmsUserCoupons = pmsCouponFeignService.bestList(totalPrice);
            orderConfirmVO.setUserCoupons(pmsUserCoupons);
        }
//        }, threadPoolExecutor);

        // 获取会员地址列表
//        CompletableFuture<Void> addressesCompletableFuture = CompletableFuture.runAsync(() -> {
        List<UmsAddress> addresses = addressFeignService.findUserAddress(memberId);
        orderConfirmVO.setAddresses(addresses);
//        }, threadPoolExecutor);

        // 生成唯一标识，防止订单重复提交
//        CompletableFuture<Void> orderTokenCompletableFuture = CompletableFuture.runAsync(() -> {
        String orderToken = businessNoGenerator.generate(BusinessTypeEnum.ORDER);
        orderConfirmVO.setOrderToken(orderToken);
        redisRepository.set(OmsConstants.ORDER_TOKEN_PREFIX + orderToken, orderToken);
//        }, threadPoolExecutor);


//        CompletableFuture.allOf(orderItemsCompletableFuture, addressesCompletableFuture, orderTokenCompletableFuture).join();

        PmsSpu spu = pmsSpuService.getById(skuFeignService.getSkuById(orderConfirmDTO.getSkuId()).getSpuId());
        orderConfirmVO.setStoreInfo(storeInfoService.baseInfo(spu.getStoreId()));

        log.info("订单确认响应：{}", orderConfirmVO.toString());
        return orderConfirmVO;
    }

    /**
     * 获取商品价格 不同营销策略下
     */
    private Long getOrderPrice(Integer orderType, Long skuId, Long skuPrice) {
        log.info("orderType = {},skuId = {} ,skuPrice = {} ", orderType, skuId, skuPrice);

        if (orderType.equals(OrderTypeEnum.SECKILL.getCode())) {
            PmsMarketingField pmsMarketingField = pmsMarketingFieldService.getBySkuId(skuId);

            return pmsMarketingField.getPrice();
        }
        if (orderType.equals(OrderTypeEnum.GROUP.getCode())) {
            PmsMarketingField pmsMarketingField = pmsMarketingFieldService.getBySkuId(skuId);

            return pmsMarketingField.getPrice();
        }
        if (orderType.equals(OrderTypeEnum.CROWDFUNDING.getCode())) {
            PmsMarketingField pmsMarketingField = pmsMarketingFieldService.getBySkuId(skuId);

            return pmsMarketingField.getPrice();
        }

        return skuPrice;
    }


    /**
     * 订单提交
     */
    @Override
//    @GlobalTransactional
    @Transactional
    public OrderSubmitVO submit(OrderSubmitDTO submitDTO) {
        log.info("=======================订单提交=======================\n订单提交信息：{}", submitDTO);
        // 订单重复提交校验
        String orderToken = submitDTO.getOrderToken();
        Long result = redisRepository.releaseLock(Collections.singletonList(OmsConstants.ORDER_TOKEN_PREFIX + orderToken), orderToken);

        if (!ObjectUtil.equals(result, OmsConstants.RELEASE_LOCK_SUCCESS_RESULT)) {
            throw new BizException("订单不可重复提交");
        }

        List<OrderItemDTO> orderItems = submitDTO.getOrderItems();
        if (CollectionUtil.isEmpty(orderItems)) {
            throw new BizException("订单没有商品，请选择商品后提交");
        }

        if (submitDTO.getOrderType() == null) {
            submitDTO.setOrderType(OrderTypeEnum.SHOP.getCode());
        }
        if (submitDTO.getOrderType().equals(OrderTypeEnum.SHOP.getCode())) {
            // 订单验价
            Long currentTotalPrice = orderItems.stream().map(item -> {
                SkuDTO sku = skuFeignService.getSkuById(item.getSkuId());
                if (sku != null) {
                    return sku.getPrice() * item.getCount();
                }
                return 0L;
            }).reduce(0L, Long::sum);

            if (currentTotalPrice.compareTo(submitDTO.getTotalPrice()) != 0) {
                throw new BizException("页面已过期，请重新刷新页面再提交");
            }

            // 优惠后价格验价
            if (submitDTO.getUserCouponId() != null) {
                PmsUserCoupon pmsUserCoupon = pmsCouponFeignService.getByUserCouponId(submitDTO.getUserCouponId());
                if (pmsUserCoupon.getUseTime() != null) {
                    throw new BizException("优惠券已使用");
                }

                // todo: 优惠券是否可用

                // todo： 优惠后金额是否正确
                if (currentTotalPrice - pmsUserCoupon.getPrice() != submitDTO.getPayAmount()) {

                    throw new BizException("优惠金额出错");
                }

                pmsCouponFeignService.useUserCoupon(submitDTO.getUserCouponId());

            }
        } else {
            // todo: 验价
            Long skuId = submitDTO.getOrderItems().get(0).getSkuId();

        }

        // 校验库存是否足够和锁库存
        List<SkuLockDTO> skuLockList = orderItems.stream()
                .map(item -> SkuLockDTO.builder().skuId(item.getSkuId())
                        .count(item.getCount())
                        .orderToken(orderToken)
                        .build())
                .collect(Collectors.toList());

        Boolean lockResult = skuFeignService.lockStock(skuLockList);

        if (!lockResult) {
            throw new BizException(Result.failed().getMsg());
        }

        // 创建订单(状态：待支付)
        Long spuId = orderItems.get(0).getSpuId();
        PmsSpu pmsSpu = pmsSpuService.getById(spuId);
        Long storeId = pmsSpu.getStoreId();
        OmsOrder order = new OmsOrder();
        order.setOrderSn(orderToken) // 把orderToken赋值给订单编号【!】
                .setStoreId(storeId)
                .setStatus(OrderStatusEnum.PENDING_PAYMENT.getCode())
                .setSourceType(OrderSourceEnum.APP.getCode())
                .setOrderType(submitDTO.getOrderType())
                .setRelativeId(submitDTO.getRelativeId())
                .setMemberId(RequestUtils.getUserId())
                .setUserCouponId(submitDTO.getUserCouponId())
                .setRemark(submitDTO.getRemark())
                .setCouponAmount(submitDTO.getTotalPrice() - submitDTO.getPayAmount())
                .setPayAmount(submitDTO.getPayAmount())
                .setTotalQuantity(orderItems.stream().map(item -> item.getCount()).reduce(0, (x, y) -> x + y))
                .setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0L, (x, y) -> x + y))
                .setGmtCreate(new Date());
        this.save(order);

        UmsAddress umsAddress = addressFeignService.getById(submitDTO.getAddressId());
        // 生成物流基本信息
        OmsOrderDelivery omsOrderDelivery = new OmsOrderDelivery()
                .setOrderId(order.getId())
                .setReceiverName(umsAddress.getName())
                .setReceiverPhone(umsAddress.getMobile())
                .setReceiverProvince(umsAddress.getProvince())
                .setReceiverCity(umsAddress.getCity())
                .setReceiverRegion(umsAddress.getArea())
                .setReceiverDetailAddress(umsAddress.getAddress())
                .setReceiverPostCode(umsAddress.getZipCode());

        orderDeliveryService.save(omsOrderDelivery);

        // 创建订单商品
        List<OmsOrderItem> orderItemList = orderItems.stream().map(item -> OmsOrderItem.builder()
                .orderId(order.getId())
                .spuId(item.getSpuId())
                .skuId(item.getSkuId())
                .skuName(item.getSkuName())
                .skuPrice(item.getPrice())
                .skuPic(item.getPic())
                .skuQuantity(item.getCount())
                .skuTotalPrice(item.getCount() * item.getPrice())
                .skuCode(item.getSkuCode())
                .build()).collect(Collectors.toList());
        orderItemService.saveBatch(orderItemList);

        // 将订单放入延时队列，超时未支付由交换机order.exchange切换到死信队列完成系统自动关单
        log.info("订单超时取消RabbitMQ消息发送，订单SN：{}", orderToken);
        rabbitTemplate.convertAndSend(OmsConstants.EXCHANGE_ORDER_EXCHANGE, OmsConstants.QUEUE_ORDER_EVENT, orderToken);

        OrderSubmitVO submitVO = new OrderSubmitVO();
        submitVO.setOrderId(order.getId());
        submitVO.setOrderSn(order.getOrderSn());
        log.info("订单提交响应：{}", submitVO.toString());
        return submitVO;
    }

    @Override
    public OrderInfoVO info(Long orderId) {
        Long memberId = RequestUtils.getUserId();
        OmsOrder result = this.getById(orderId);
        OrderInfoVO orderInfoVO = new OrderInfoVO();
        orderInfoVO.setOrderId(orderId);
        orderInfoVO.setTotalPrice(result.getTotalAmount());
        orderInfoVO.setPayAmount(result.getPayAmount());
        Long balance = umsUserService.getBalance(memberId);
        orderInfoVO.setTotalBalance(balance);

        // 查询订单对应的商家的支付配置
        StorePayInfoConfig storePayInfoVo = storePayInfoService.getStorePayConfig(result.getStoreId());
        orderInfoVO.setStorePayInfoVo(storePayInfoVo);

        return orderInfoVO;
    }

    /**
     * 订单支付
     *
     * @param orderId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean pay(Long orderId) {

        OmsOrder order = this.getById(orderId);
        if (order != null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
            throw new BizException("支付失败，请检查订单状态");
        }

        // 扣减余额
        Long userId = RequestUtils.getUserId();
        Long payAmount = order.getPayAmount();
        boolean deductBalanceResult = umsUserService.deductBalance(userId, payAmount);
        if (!deductBalanceResult) {
            throw new BizException("扣减账户余额失败");
        }

        // 扣减库存
        boolean deductStockResult = skuFeignService.deductStock(order.getOrderSn());
        if (!deductStockResult) {
            throw new BizException("扣减商品库存失败");
        }


        List<OmsOrderItem> orderItems = orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, orderId));
        for (OmsOrderItem item : orderItems) {
            skuFeignService.addSales(item.getSpuId(), item.getSkuQuantity());
        }

        OrderTypeEnum orderTypeEnum = OrderTypeEnum.getValue(order.getOrderType());
        OrderStatusEnum orderStatusEnum = OrderStatusEnum.PENDING_SHIPPED;
        // todo:
        switch (orderTypeEnum) {
            case SECKILL:
                orderStatusEnum = OrderStatusEnum.PAID;
                // 营销场人数和金额累加
                pmsMarketingFieldService.addBuyNumsAndMoney(order.getRelativeId());
                break;
            case GROUP:
            case CROWDFUNDING:
                orderStatusEnum = OrderStatusEnum.PAID;
                order.setStatus(OrderStatusEnum.PAID.getCode());
                // 营销场人数和金额累加
                pmsMarketingFieldService.addBuyNumsAndMoney(order.getRelativeId());

                // 是否团购或众筹成功
                PmsMarketingField pmsMarketingField = pmsMarketingFieldService.getDetailById(order.getRelativeId());
                if (pmsMarketingField.isSuccess()) {
                    orderStatusEnum = OrderStatusEnum.PENDING_SHIPPED;
                }

                break;
        }

        // 更新订单状态
        order.setStatus(orderStatusEnum.getCode());
        order.setPayType(PayTypeEnum.BALANCE.getCode());
        order.setPayTime(new Date());
        this.updateById(order);


        // 支付成功删除购物车已勾选的商品
        cartService.removeCheckedItem();

        return true;
    }

    /**
     * 订单积分支付
     *
     * @param orderId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean payPoint(Long orderId) {

        OmsOrder order = this.getById(orderId);
        if (order != null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
            throw new BizException("支付失败，请检查订单状态");
        }

        // 积分是否足够
        Long userPoint = umsUserService.getPoint(RequestUtils.getUserId());
        if (userPoint.compareTo(order.getPayPointAmount()) < 0) {
            throw new BizException("会员积分不够");
        }

        // 扣减库存
        boolean deductStockResult = skuFeignService.deductStock(order.getOrderSn());
        if (!deductStockResult) {
            throw new BizException("扣减商品库存失败");
        }

        PmsPointThing pmsPointThing = pmsPointThingFeignService.getPointThingById(order.getRelativeId());


        List<OmsOrderItem> orderItems = orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, orderId));
        for (OmsOrderItem item : orderItems) {
            skuFeignService.addSales(item.getSpuId(), item.getSkuQuantity());
        }

        // 更新订单状态
        order.setStatus(OrderStatusEnum.PENDING_SHIPPED.getCode());
        order.setPayType(PayTypeEnum.POINT.getCode());
        order.setPayTime(new Date());
        order.setPayAmount(0L);
        order.setPayPointAmount(pmsPointThing.getPoint());
        this.updateById(order);

        // 兑换记录
        pmsPointThingFeignService.addPointThing(pmsPointThing.getId());

        // 积分扣除
        umsUserService.updatePoint(pmsPointThing.getPoint(), PointOperatingEnum.PRODUCT_EXCHANGE.getCode());
        return true;
    }

    private final WeiXinPayClientService weiXinPayClientService;

    @Override
    public String payByWeiXin(Long orderId) {
        OmsOrder order = this.getById(orderId);
        if (order == null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
            throw new BizException("支付失败，请检查订单状态");
        }

        // 获取支付用户信息
        Long memberId = order.getMemberId();
        UmsUserDto umsUserDto = umsUserService.getUserDtoById(memberId);
        String openid = umsUserDto.getOpenid();

        // 获取店铺信息
        StoreInfoDto storeInfoDto = storeInfoService.getStoreInfoDtoById(order.getStoreId());


//        String result = weiXinPayClientService.jsApiPay(openid);
//            openId     支付方openId

//      sysTradeNo 系统订单号
        String sysTradeNo = order.getOrderSn();
//     subAppId   子商家
        String subAppId = weAppConfig.getAppid();
//      subMchId   微信支付分配的子商户号
        String subMchId = storeInfoDto.getStorePayInfo().getWxSubMchId();
//      orderTotal 订单总金额,单位分
        Integer orderTotal = order.getPayAmount().intValue();
//            description 描述
        String description = "测试商品";
//     attach 自定义参数
        String attach = "";
        String result = weiXinPayClientService.jsApiPay(openid, sysTradeNo, subAppId, subMchId, orderTotal, description, attach);
        log.info("result = {}", result);
        return result;
    }

    @Override
    public void payByAlipay(Long orderId) {

    }

    @Override
    public boolean closeOrder(String orderToken) {
        log.info("=======================订单关闭，订单SN：{}=======================", orderToken);
        OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>()
                .eq(OmsOrder::getOrderSn, orderToken));
        if (order == null || !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
            return false;
        }
        order.setStatus(OrderStatusEnum.AUTO_CANCEL.getCode());
        return this.updateById(order);
    }

    @Override
    public boolean cancelOrder(Long id) {

        Long userId = RequestUtils.getUserId();

        log.info("=======================订单取消，订单ID：{}=======================", id);
        OmsOrder order = this.getById(id);

        if (!order.getMemberId().equals(userId)) {
            throw new BizException("取消失败，订单不属于该用户"); // 通过自定义异常，将异常信息抛出由异常处理器捕获显示给前端页面
        }

        if (order != null && !OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
            throw new BizException("取消失败，订单状态不支持取消"); // 通过自定义异常，将异常信息抛出由异常处理器捕获显示给前端页面
        }
        order.setStatus(OrderStatusEnum.USER_CANCEL.getCode());
        boolean result = this.updateById(order);
        if (result) {
            // 释放被锁定的库存
            boolean unlockResult = skuFeignService.unlockStock(order.getOrderSn());
            if (!unlockResult) {
                throw new BizException("系统异常");
            }

            // todo: 返回优惠券


            result = true;
        }
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteOrder(Long id) {
        log.info("=======================订单删除，订单ID：{}=======================", id);
        OmsOrder order = this.getById(id);
        Long userId = RequestUtils.getUserId();
        if (!order.getMemberId().equals(userId)) {
            throw new BizException("删除失败，订单不属于该用户"); // 通过自定义异常，将异常信息抛出由异常处理器捕获显示给前端页面
        }
        if (order != null && !OrderStatusEnum.AUTO_CANCEL.getCode().equals(order.getStatus()) && !OrderStatusEnum.USER_CANCEL.getCode().equals(order.getStatus())) {
            throw new BizException("订单删除失败，订单不存在或订单状态不支持删除");
        }
        return this.removeById(id);
    }


    @Override
    public IPage<OmsOrder> list(Page<OmsOrder> page, OmsOrder order) {
        List<OmsOrder> list = this.baseMapper.list(page, order);
        page.setRecords(list);
        return page;
    }


    @Override
    public boolean deliver(Long orderId, String deliveryCompany, String deliverySn) {
        OmsOrderDelivery omsOrderDelivery = orderDeliveryService.getOne(new LambdaQueryWrapper<OmsOrderDelivery>().eq(OmsOrderDelivery::getOrderId, orderId));
        omsOrderDelivery.setDeliveryCompany(deliveryCompany);
        omsOrderDelivery.setDeliverySn(deliverySn);
        omsOrderDelivery.setDeliveryTime(new Date());

        OmsOrder omsOrder = this.getById(orderId);
        omsOrder.setStatus(OrderStatusEnum.DELIVERED.getCode());
        this.saveOrUpdate(omsOrder);
        return orderDeliveryService.saveOrUpdate(omsOrderDelivery);
    }


    @Override
    public boolean receipt(Long orderId) {

        OmsOrder omsOrder = this.getById(orderId);
        omsOrder.setReceiveTime(new Date());
        omsOrder.setStatus(OrderStatusEnum.FINISHED.getCode());
        return this.saveOrUpdate(omsOrder);
    }

    @Override
    public String findDelivery(Long orderId) {
        Object object = redisRepository.get(OmsConstants.ORDER_DELIVERY_PREFIX + orderId);
        String result = object == null ? "" : object.toString();
        if (StrUtil.isNotBlank(result)) {
            return result;
        }
        OmsOrderDelivery omsOrderDelivery = orderDeliveryService.getOne(new LambdaQueryWrapper<OmsOrderDelivery>().eq(OmsOrderDelivery::getOrderId, orderId));
        result = GlobalExpressUtil.findDelivery(omsOrderDelivery.getDeliveryCompany(), omsOrderDelivery.getDeliverySn(), omsOrderDelivery.getReceiverPhone());
        redisRepository.setExpire(OmsConstants.ORDER_DELIVERY_PREFIX + orderId, result, 3600);
        return result;
    }

    /**
     * 商家查看订单
     *
     * @param page    当前页
     * @param limit   每页条数
     * @param orderSn 订单号
     * @param status  订单状态【101->待付款；102->用户取消；103->系统取消；201->已付款；202->申请退款；203->已退款；301->待发货；401->已发货；501->用户收货；502->系统收货；901->已完成】
     * @return 订单数据
     */
    @Override
    public IPage<OmsOrder> orderListByStore(Long page, Long limit, String orderSn, Integer status) {
        Long userId = RequestUtils.getUserId();
        SysUserDto sysUserDto = sysUserService.getSysUserDtoById(RequestUtils.getUserId());
        check(sysUserDto);

        IPage<OmsOrder> result = findOrderList(page, limit, orderSn, status, sysUserDto.getStoreId(), null);

        log.info("userId = {},result = {}", userId, result);
        return result;
    }

    /**
     * 管理员获取订单
     *
     * @param page    当前页
     * @param limit   每页条数
     * @param orderSn 订单号
     * @param status  订单状态【101->待付款；102->用户取消；103->系统取消；201->已付款；202->申请退款；203->已退款；301->待发货；401->已发货；501->用户收货；502->系统收货；901->已完成】
     * @param storeId 商家ID
     * @return 订单数据
     */
    @Override
    public IPage<OmsOrder> orderListByAdmin(Long page, Long limit, String orderSn, Integer status, Long storeId) {
        Long userId = RequestUtils.getUserId();
        IPage<OmsOrder> result = findOrderList(page, limit, orderSn, status, storeId, null);

        log.info("userId = {},result = {}", userId, result);
        return result;

    }

    @Override
    public IPage<OmsRefundOrderVo> refundOrderListByStore(Long page, Long limit, String orderSn, Integer selectStatus) {
        Long userId = RequestUtils.getUserId();
        SysUserDto sysUserDto = sysUserService.getSysUserDtoById(userId);
        if (!sysUserDto.getHaveStore()) {
            throw new BizException("您还不是店家");
        }

        return getOmsRefundOrderVoPage("store", page, limit, orderSn, sysUserDto.getStoreId(), selectStatus, userId);
    }

    @Override
    public IPage<OmsRefundOrderVo> refundOrderListByAdmin(Long page, Long limit, String orderSn, Long storeId, Integer selectStatus) {

        return getOmsRefundOrderVoPage("admin", page, limit, orderSn, storeId, selectStatus, null);
    }


    @Override
    public OmsOrder getOrderByOrderSnForPcc(String orderSn) {
        return this.getBaseMapper().getOrderByOrderSnForPcc(orderSn);
    }

    /**
     * 微信支付回调
     *
     * @param request  请求
     * @param response 响应
     */
    @Override
    public void wxPayNotify(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String> map = new HashMap<>(12);
        try {
            String timestamp = request.getHeader("Wechatpay-Timestamp");
            String nonce = request.getHeader("Wechatpay-Nonce");
            String serialNo = request.getHeader("Wechatpay-Serial");
            String signature = request.getHeader("Wechatpay-Signature");

            log.info("timestamp:{} nonce:{} serialNo:{} signature:{}", timestamp, nonce, serialNo, signature);
            String result = HttpKit.readData(request);
            log.info("支付通知密文 {}", result);

            // 需要通过证书序列号查找对应的证书，verifyNotify 中有验证证书的序列号
            String plainText = WxPayKit.verifyNotify(serialNo, result, signature, nonce, timestamp,
                    wxPayConfig.getApiKey3(), wxPayConfig.getSpWxCert());

            log.info("支付通知明文 {}", plainText);

            Map<String, Object> paramMap = JsonUtil.string2Collection(plainText, new TypeReference<Map<String, Object>>() {
            });


            String orderSn = (String) paramMap.get("out_trade_no");
            // 悲观锁保证 幂等性
            OmsOrder order = this.getOrderByOrderSnForPcc(orderSn);

            // 扣减库存
            boolean deductStockResult = skuFeignService.deductStock(order.getOrderSn());
            if (!deductStockResult) {
                throw new BizException("扣减商品库存失败");
            }


            List<OmsOrderItem> orderItems = orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, order.getId()));
            for (OmsOrderItem item : orderItems) {
                skuFeignService.addSales(item.getSpuId(), item.getSkuQuantity());
            }

            OrderTypeEnum orderTypeEnum = OrderTypeEnum.getValue(order.getOrderType());
            OrderStatusEnum orderStatusEnum = OrderStatusEnum.PENDING_SHIPPED;
            // todo:
            switch (orderTypeEnum) {
                case SECKILL:
                    orderStatusEnum = OrderStatusEnum.PAID;
                    // 营销场人数和金额累加
                    pmsMarketingFieldService.addBuyNumsAndMoney(order.getRelativeId());
                    break;
                case GROUP:
                case CROWDFUNDING:
                    orderStatusEnum = OrderStatusEnum.PAID;
                    order.setStatus(OrderStatusEnum.PAID.getCode());
                    // 营销场人数和金额累加
                    pmsMarketingFieldService.addBuyNumsAndMoney(order.getRelativeId());

                    // 是否团购或众筹成功
                    PmsMarketingField pmsMarketingField = pmsMarketingFieldService.getDetailById(order.getRelativeId());
                    if (pmsMarketingField.isSuccess()) {
                        orderStatusEnum = OrderStatusEnum.PENDING_SHIPPED;
                    }

                    break;
            }

            // 更新订单状态
            order.setStatus(orderStatusEnum.getCode());
            order.setPayType(PayTypeEnum.WEIXIN.getCode());
            order.setPayTime(new Date());
            boolean updateOrder = this.updateById(order);


            // 支付成功删除购物车已勾选的商品
//        cartService.removeCheckedItem();

            if (StrUtil.isNotEmpty(plainText) && updateOrder) {
                response.setStatus(200);
                map.put("code", "SUCCESS");
                map.put("message", "SUCCESS");
            } else {
                response.setStatus(500);
                map.put("code", "ERROR");
                map.put("message", "签名错误");
            }
            response.setHeader("Content-type", ContentType.JSON.toString());
            response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
            response.flushBuffer();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 根据订单ID获取商品列表
     */
    @Override
    public ShowOrderVo findSpuByOrderId(Long orderId) {

        // 查询订单
        OmsOrder omsOrder = this.getById(orderId);
        log.info("omsOrder = {}", omsOrder);
        if (ObjectUtils.isEmpty(omsOrder)) {
            log.info("orderId = {}", orderId);
            throw new BizException("数据不存在");
        }

        // 订单商品信息
        List<OmsOrderItem> orderItemList = orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>()
                .eq(OmsOrderItem::getOrderId, orderId)
        );

        List<OmsOrderItemVo> orderItemVoList = orderItemList.stream().map(item -> {
            OmsOrderItemVo omsOrderItemVo = new OmsOrderItemVo();
            BeanUtil.copyProperties(item, omsOrderItemVo);
            return omsOrderItemVo;
        }).collect(Collectors.toList());

        // 组装数据
        ShowOrderVo showOrderVo = new ShowOrderVo();
        BeanUtil.copyProperties(omsOrder, showOrderVo);
        showOrderVo.setOrderItemList(orderItemVoList);

        return showOrderVo;
    }


    /**
     * 保存订单商品评论
     */
    @Override
    public Boolean saveComment(OrderCommentForm form) {
        log.info("form = {}", form);
        // 用户信息
        Long userId = RequestUtils.getUserId();
        UmsUserDto userDto = umsUserService.getUserDtoById(userId);
        String userName = userDto.getNickname();
        String avatar = userDto.getAvatar();

        //订单信息
        Long orderId = form.getOrderId();
        OmsOrder omsOrder = this.getById(orderId);
        log.info("omsOrder = {}", omsOrder);
        if (ObjectUtils.isEmpty(omsOrder)) {
            log.info("orderId = {}", orderId);
            throw new BizException("数据不存在");
        }
        Boolean commented = omsOrder.getCommented();
        if (commented) {
            // 目前系统是单订单 单商品,直接判断是否评价过
            throw new BizException("该商品您已经评价过了");
        }

        // 订单子项信息
        List<OmsOrderItem> orderItemList = orderItemService.getByOrderId(orderId);
        log.info("orderItemList = {}", orderItemList);

        // 店铺信息
        StoreInfoDto storeInfoDto = storeInfoService.getStoreInfoDtoById(omsOrder.getStoreId());

        List<OmsOrderCommentForm> orderCommentFormList = form.getOrderCommentList();
        List<OmsOrderComment> orderCommentList = new ArrayList<>();
        for (OmsOrderCommentForm commentForm : orderCommentFormList) {
            OmsOrderComment omsOrderComment = new OmsOrderComment();
            BeanUtil.copyProperties(commentForm, omsOrderComment);

            omsOrderComment.setOrderId(orderId);
            omsOrderComment.setStoreId(storeInfoDto.getId());
            omsOrderComment.setStoreName(storeInfoDto.getStoreName());
            omsOrderComment.setUserId(userId);
            omsOrderComment.setUserName(userName);
            omsOrderComment.setUserAvatar(avatar);

            for (OmsOrderItem orderItem : orderItemList) {

                log.info("spuId = {},{}", commentForm.getSpuId(), orderItem.getSpuId());
                // 匹配商品 & 商品未被评价过
                if (commentForm.getSpuId().equals((long) orderItem.getSpuId())) {
                    // 商品sku名称(冗余快照)
                    omsOrderComment.setSkuName(orderItem.getSkuName());
                    // 商品sku总价
                    omsOrderComment.setSkuTotalPrice(orderItem.getSkuTotalPrice());
                    // 商品主图
                    omsOrderComment.setPicUrl(orderItem.getSkuPic());
                    log.info("omsOrderComment = {}", omsOrderComment);
                    // 修改是否评价过状态
                    orderItem.setSubCommented(true);
                }
            }
            orderCommentList.add(omsOrderComment);
        }

        boolean saveBatch = commentService.saveListComment(orderCommentList);

        log.info("orderItemList = {}", orderItemList);
        //修改订单子项的是否评价状态
        boolean isUpdateCommentStatus = orderItemService.updateBatchById(orderItemList);
        // 修改订单的是否评价状态
        omsOrder.setCommented(true);
        boolean updateOrder = this.updateById(omsOrder);

        log.info("saveBatch = {}", saveBatch);
        return saveBatch && isUpdateCommentStatus && updateOrder;
    }

    /**
     * 商品所有的评论列表
     */
    @Override
    public Page<OmsOrderCommentVo> findCommentBySpuId(Long spuId, Integer page, Integer limit) {
        PmsSpu pmsSpu = pmsSpuService.getById(spuId);
        if (ObjectUtils.isEmpty(pmsSpu)) {
            throw new BizException("商品不存在");
        }

        Page<OmsOrderComment> commentPage = commentService.page(new Page<>(page, limit), new LambdaQueryWrapper<OmsOrderComment>()
                .eq(OmsOrderComment::getSpuId, spuId)
                .eq(OmsOrderComment::getReviewStatus, ReviewStatusEnum.PASS.getCode())
                .orderByDesc(OmsOrderComment::getGmtModified)
                .orderByDesc(OmsOrderComment::getGmtCreate)
        );

        Page<OmsOrderCommentVo> voPage = new Page<>(page, limit, commentPage.getTotal());

        List<OmsOrderCommentVo> voList = commentPage.getRecords().stream().map(comment -> {
            OmsOrderCommentVo vo = new OmsOrderCommentVo();
            BeanUtil.copyProperties(comment, vo);
            vo.setImagers(ImagerListUtil.conversionToList(comment.getImagerList()));
            return vo;
        }).collect(Collectors.toList());

        for (OmsOrderCommentVo omsOrderComment : voList) {

            List<OmsOrderCommentReply> replyList = replyMapper.selectList(new LambdaQueryWrapper<OmsOrderCommentReply>()
                    .eq(OmsOrderCommentReply::getOrderCommentId, omsOrderComment.getId())
            );
            List<OmsOrderCommentReplyVo> replyVoList = replyList.stream().map(reply -> {
                OmsOrderCommentReplyVo replyVo = new OmsOrderCommentReplyVo();
                BeanUtil.copyProperties(reply, replyVo);
                return replyVo;
            }).collect(Collectors.toList());

            omsOrderComment.setReplyList(replyVoList);
        }

        voPage.setRecords(voList);

        return voPage;
    }

    /**
     * 我的评论
     */
    @Override
    public Page<OmsOrderCommentVo> findMyComment(Integer page, Integer limit) {
        Long userId = RequestUtils.getUserId();
        log.info("userId = {}", userId);

        Page<OmsOrderComment> commentPage = commentService.page(new Page(page, limit), new LambdaQueryWrapper<OmsOrderComment>()
                .eq(OmsOrderComment::getUserId, userId)
        );

        List<OmsOrderCommentVo> voList = commentPage.getRecords().stream().map(pojo -> {
            OmsOrderCommentVo vo = new OmsOrderCommentVo();
            BeanUtil.copyProperties(pojo, vo);
            vo.setImagers(ImagerListUtil.conversionToList(pojo.getImagerList()));
            return vo;
        }).collect(Collectors.toList());

        Page<OmsOrderCommentVo> omsOrderCommentVoPage = new Page<>(page, limit, commentPage.getTotal());

        omsOrderCommentVoPage.setRecords(voList);

        return omsOrderCommentVoPage;
    }

    @Override
    public List<RefundAndAfterSaleVo> refundAndAfterSale(Long orderId) {
        OmsOrder omsOrder = this.getById(orderId);
        List<RefundAndAfterSaleVo> voList = new ArrayList<>();

        OrderStatusEnum anEnum = OrderStatusEnum.getValue(omsOrder.getStatus());
        switch (anEnum) {
            case PAID:
            case PENDING_SHIPPED:
                voList.add(RefundAndAfterSaleVo.builder().code(RefundAndAfterSaleEnum.ONLY_REFUND.getCode())
                        .title(RefundAndAfterSaleEnum.ONLY_REFUND.getTitle())
                        .depict(RefundAndAfterSaleEnum.ONLY_REFUND.getDepict())
                        .logoUrl(RefundAndAfterSaleEnum.ONLY_REFUND.getLogoUrl())
                        .build());
                return voList;

            case DELIVERED:
            case FINISHED:
                voList.add(RefundAndAfterSaleVo.builder().code(RefundAndAfterSaleEnum.ONLY_REFUND.getCode())
                        .title(RefundAndAfterSaleEnum.ONLY_REFUND.getTitle())
                        .depict(RefundAndAfterSaleEnum.ONLY_REFUND.getDepict())
                        .logoUrl(RefundAndAfterSaleEnum.ONLY_REFUND.getLogoUrl())
                        .build());
                voList.add(RefundAndAfterSaleVo.builder().code(RefundAndAfterSaleEnum.REFUND_AND_GOODS.getCode())
                        .title(RefundAndAfterSaleEnum.REFUND_AND_GOODS.getTitle())
                        .depict(RefundAndAfterSaleEnum.REFUND_AND_GOODS.getDepict())
                        .logoUrl(RefundAndAfterSaleEnum.REFUND_AND_GOODS.getLogoUrl())
                        .build());
                return voList;
            default:
                return voList;
        }
    }

    /**
     * 查看订单
     *
     * @param page    当前页
     * @param limit   每页条数
     * @param orderSn 订单号
     * @param status  订单状态 订单状态【101->待付款；102->用户取消；103->系统取消；201->已付款；202->申请退款；203->已退款；301->待发货；401->已发货；501->用户收货；502->系统收货；901->已完成】
     * @param storeId 店铺ID
     * @return 订单数据
     */
    private IPage<OmsOrder> findOrderList(Long page, Long limit, String orderSn, Integer status, Long storeId, Boolean refund) {

        IPage<OmsOrder> result = this.page(new Page<>(page, limit), new LambdaQueryWrapper<OmsOrder>()
                .eq(StrUtil.isNotBlank(orderSn), OmsOrder::getOrderSn, orderSn)
                .eq(ObjectUtil.isNotNull(status), OmsOrder::getStatus, status)
                .eq(ObjectUtil.isNotNull(storeId), OmsOrder::getStoreId, storeId)
                .eq(ObjectUtil.isNotNull(refund), OmsOrder::getRefund, refund)
                .orderByDesc(OmsOrder::getGmtCreate)
        );

        for (OmsOrder omsOrder : result.getRecords()) {
            omsOrder.setOrderItems(orderItemService.list(new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, omsOrder.getId())));
        }

        return result;
    }

    /**
     * 退款订单
     *
     * @param type         商家 / 管理员
     * @param page         当前页
     * @param limit        每页条数
     * @param orderSn      订单号
     * @param storeId      店铺ID
     * @param selectStatus 查询状态 1申请中 2 已完成
     * @param userId       操作用户ID
     * @return 申请的退款订单
     */
    private Page<OmsRefundOrderVo> getOmsRefundOrderVoPage(String type, Long page, Long limit, String orderSn, Long storeId, Integer selectStatus, Long userId) {
        if (selectStatus < 0 || selectStatus > 2) {
            throw new BizException("查询类型错误");
        }

        Integer status = null;
        if (selectStatus.equals(2)) {
            status = OrderStatusEnum.SHUTDOWN.getCode();
        }
        IPage<OmsOrder> pojoPage = findOrderList(page, limit, orderSn, status, storeId, true);

        log.info("list = {}", pojoPage.getRecords());

        List<OmsRefundOrderVo> voList = pojoPage.getRecords().stream().map(pojo -> {
            OmsRefundOrderVo vo = new OmsRefundOrderVo();
            BeanUtil.copyProperties(pojo, vo);
            OmsOrderRefundVo orderRefundVo = orderRefundService.getDetail(pojo.getId(), pojo.getOrderItems().get(0).getId());
            vo.setOrderRefund(orderRefundVo);
            return vo;
        }).collect(Collectors.toList());

        Page<OmsRefundOrderVo> voPage = new Page<>(page, limit, pojoPage.getTotal());
        voPage.setRecords(voList);

        log.info("userId = {},voPage.size = {}", RequestUtils.getUserId(), voPage.getTotal());

        return voPage;
    }


    private void check(SysUserDto userDto) {
        //检验是否是商家账号
        log.info("haveStore = {} ,userDto = {} ", userDto.getHaveStore(), userDto);
        if (ObjectUtils.isEmpty(userDto) || !userDto.getHaveStore()) {
            throw new BizException("您还不是商家,权限不足");
        }

        // 检验商店状态 是否是开店
        StoreInfoDto storeInfoDto = userDto.getStoreInfoDto();
        System.out.println("storeInfoDto = " + storeInfoDto);
        Integer storeEventStatus = storeInfoDto.getStoreEventStatus();
        if (1 == storeEventStatus) {
            throw new BizException("您的店铺已关闭,暂无权限发布商品");
        }

        ReviewStatusEnum anEnum = ReviewStatusEnum.getValue(storeInfoDto.getReviewStatus());
        switch (Objects.requireNonNull(anEnum)) {
            case PASS:
                break;
            case UN_KNOWN:
                throw new BizException("您的店铺还未审核,请耐心等待");
            case NO_PASS:
                throw new BizException("您提交的店铺资料有问题,请重新提交");
            default:
                throw new BizException("店铺审核状态异常");
        }
    }
}
